{{define "infoCollection/family.html"}}
<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">家族史</h3>
    </div>

    <form class="form-horizontal" id="familyForm">
        <div class="form-group">
            <label class="control-label col-sm-2">
                脑卒中（中风）:
            </label>
            <div class="radio col-sm-10">
                <input type="radio" name="jiazushi_zhongfeng" value="无" class="minimal" checked>&nbsp;&nbsp;无
                <input type="radio" name="jiazushi_zhongfeng" value="有" class="minimal">&nbsp;&nbsp;有
                <input type="radio" name="jiazushi_zhongfeng" value="不详" class="minimal">&nbsp;&nbsp;不详
            </div>
        </div>
        <div class="form-group" id="jiazushi_zhongfeng_relation" style="display: none;">
            <div class="radio col-sm-offset-2 col-sm-10">
                <span style="color: red;font-weight: bold;">与本人关系:&nbsp;&nbsp;</span>
                <input type="checkbox" name="jiazushi_zhongfeng_relation" value="父亲" class="minimal">&nbsp;父亲
                <input type="checkbox" name="jiazushi_zhongfeng_relation" value="母亲" class="minimal">&nbsp;母亲
                <input type="checkbox" name="jiazushi_zhongfeng_relation" value="兄弟姐妹" class="minimal">&nbsp;兄弟姐妹
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-sm-2">
                冠心病:
            </label>
            <div class="radio col-sm-10">
                <input type="radio" name="jiazushi_guanxinbing" value="无" class="minimal" checked>&nbsp;&nbsp;无
                <input type="radio" name="jiazushi_guanxinbing" value="有" class="minimal">&nbsp;&nbsp;有
                <input type="radio" name="jiazushi_guanxinbing" value="不详" class="minimal">&nbsp;&nbsp;不详
            </div>
        </div>
        <div class="form-group" id="jiazushi_guanxinbing_relation" style="display: none;">
            <div class="radio col-sm-offset-2 col-sm-10">
                <span style="color: red;font-weight: bold;">与本人关系:&nbsp;&nbsp;</span>
                <input type="checkbox" name="jiazushi_guanxinbing_relation" value="父亲" class="minimal">&nbsp;父亲
                <input type="checkbox" name="jiazushi_guanxinbing_relation" value="母亲" class="minimal">&nbsp;母亲
                <input type="checkbox" name="jiazushi_guanxinbing_relation" value="兄弟姐妹" class="minimal">&nbsp;兄弟姐妹
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-sm-2">
                高血压:
            </label>
            <div class="radio col-sm-10">
                <input type="radio" name="jiazushi_gaoxueya" value="无" class="minimal" checked>&nbsp;&nbsp;无
                <input type="radio" name="jiazushi_gaoxueya" value="有" class="minimal">&nbsp;&nbsp;有
                <input type="radio" name="jiazushi_gaoxueya" value="不详" class="minimal">&nbsp;&nbsp;不详
            </div>
        </div>
        <div class="form-group" id="jiazushi_gaoxueya_relation" style="display: none;">
            <div class="radio col-sm-offset-2 col-sm-10">
                <span style="color: red;font-weight: bold;">与本人关系:&nbsp;&nbsp;</span>
                <input type="checkbox" name="jiazushi_gaoxueya_relation" value="父亲" class="minimal">&nbsp;父亲
                <input type="checkbox" name="jiazushi_gaoxueya_relation" value="母亲" class="minimal">&nbsp;母亲
                <input type="checkbox" name="jiazushi_gaoxueya_relation" value="兄弟姐妹" class="minimal">&nbsp;兄弟姐妹
            </div>
        </div>


        <div class="form-group">
            <label class="control-label col-sm-2">
                糖尿病:
            </label>
            <div class="radio col-sm-10">
                <input type="radio" name="jiazushi_tangniaobing" value="无" class="minimal" checked>&nbsp;&nbsp;无
                <input type="radio" name="jiazushi_tangniaobing" value="有" class="minimal">&nbsp;&nbsp;有
                <input type="radio" name="jiazushi_tangniaobing" value="不详" class="minimal">&nbsp;&nbsp;不详
            </div>
        </div>
        <div class="form-group" id="jiazushi_tangniaobing_relation" style="display: none;">
            <div class="radio col-sm-offset-2 col-sm-10">
                <span style="color: red;font-weight: bold;">与本人关系:&nbsp;&nbsp;</span>
                <input type="checkbox" name="jiazushi_tangniaobing_relation" value="父亲" class="minimal">&nbsp;父亲
                <input type="checkbox" name="jiazushi_tangniaobing_relation" value="母亲" class="minimal">&nbsp;母亲
                <input type="checkbox" name="jiazushi_tangniaobing_relation" value="兄弟姐妹" class="minimal">&nbsp;兄弟姐妹
            </div>
        </div>


        <div class="box-footer">
            <button type="button" class="btn btn-info btn-lg middleBtn" id="familySignIn" onclick="saveFamily()">保存</button>
        </div>
    </form>
</div>

<script>
    $(function () {
        if (canUpdate != null && canUpdate != undefined && !canUpdate) {
            $("#familySignIn").hide();
        }
        familyPage("jiazushi_zhongfeng");
        familyPage("jiazushi_guanxinbing");
        familyPage("jiazushi_gaoxueya");
        familyPage("jiazushi_tangniaobing");
    });

    function familyPage(name) {
        $("input:radio[name='" + name + "']").on('ifChanged', function (event) {
            if ($(this).is(':checked')) {
                if ($(this).val() == "有") {
                    $("#" + name + "_relation").show();
                } else {
                    $("#" + name + "_relation").hide();
                    clearRelationData(name);
                }
            }
        });
    }

    function clearRelationData(name) {
        $("input:checkbox[name='" + name + "_relation']").iCheck("uncheck");
    }

    function saveFamily() {
        let d = {};
        let t = $('#familyForm').serializeArray();
        $.each(t, function () {
            if (this.value != "") {
                d[this.name] = this.value;
            }
        });
        getCheckboxValue("jiazushi_zhongfeng_relation",d);
        getCheckboxValue("jiazushi_guanxinbing_relation",d);
        getCheckboxValue("jiazushi_gaoxueya_relation",d);
        getCheckboxValue("jiazushi_tangniaobing_relation",d);
        let data = JSON.stringify(d);
        console.log("familyData:", data);
        ajaxLoading("正在保存数据......");
        $.post("/infoCollection/save", {type: "family", id: $("#screenId").val(), data: data}, function (resp) {
            ajaxLoadEnd();
            afterUpdateFormData(resp,"family");
        });
    }

    function familyInit(familyData) {
        $("#familyForm").initForm({jsonValue: familyData, isDebug: false});
    }
</script>
{{end}}